import math
q=str(input())
w=int(q)
t=0
if len(q)!=4 or w<0:
    print(0)
g=q[0]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    t=v
g=q[1]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    n=v
    if n>t:
        t=n
g=q[2]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    m=v
    if m>t:
        t=m
g=q[3]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    z=v
    if z>t:
        t=z

g=q[0] + q[1]
v=int(g)
for c in range(2,int(v**0.5)+1):
    if v%c==0:
        break
else:
    y=v
    if y>t:
        t=y
g=q[0] + q[1] + q[2]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    l = v
    if l > t:
        t = l
g=q[0] + q[1] + q[2] + q[3]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    s = v
    if s > t:
        t = s

g=q[1] + q[2]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    k = v
    if k > t:
        t = k
g=q[1] + q[2] + q[3]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    a = v
    if a > t:
        t = a
g=q[2] + q[3]
v=int(g)
for c in range(2, int(v ** 0.5) + 1):
    if v % c == 0:
        break
else:
    f = v
    if f > t:
        t = f
if t == 0:
    print(0)
else:
    print(t)
